<template>
    <div class="cate-box">
        <!-- header -->
        <my-header :title="title"></my-header>
        <!-- islogin -->
        <div class="cart-login-tip">
            <span>登录后将保存需求清单商品</span>
            <span class="login-btn">登录</span>
        </div>
        <!-- contain -->
        <div class="cart-item-contain" v-if="shopCar.carList + 1 !== [] + 1">
            <!-- title -->
            <div class="cart-item-title">
                <span><van-checkbox v-model="allChecked">健客大药房网订店送</van-checkbox></span>
                <span class="cart-item-rxtips">您的订单交由健客线下药店委托第三方快递为您配送</span>
            </div>
            <!-- body -->
            <div class="cart-item-body">
                <div class="item" v-for="item in shopCar.carList.merchantPromo[0].promo" :key="item.productCode">
                    <div class="item-info">
                        <van-checkbox v-model="allChecked" class="litteXB"></van-checkbox>
                        <van-card
                            :num="item.productNum"
                            :price="item.singlePromo.price / 100"
                            :desc="'规格：' + item.packing"  
                            :title="item.productName"
                            thumb="https://image.jianke.com/nopic.gif"
                            :origin-price="item.singlePromo.promoPrice / 100"
                            @click="toLook(item.productCode)" >
                            <div slot="footer">
                                <van-button size="mini">移入收藏夹</van-button>
                                <van-button size="mini">删除</van-button>
                            </div>
                        </van-card>
                    </div>
                    <div class="item-gift" v-if="item.gifts != ''">
                        <div class="item-gift-title">【赠品】</div>
                        <ul class="item-gift-text">
                            <li v-for="it in item.gifts" :key="it.productCode">
                                <span class="gift-name">{{it.productName}}</span>
                                <span class="gift-quantity">x{{it.productNum}}</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <!-- van-submit-bar -->
        <van-submit-bar
            :price="countPrice"
            button-text="结算"
            @submit="onSubmit">
            <van-checkbox v-model="allChecked">全选</van-checkbox>
        </van-submit-bar>
        <!-- footer -->
        <my-footer :page="page"></my-footer>
    </div>
</template>

<script>
import myHeader from 'Components/common/myHeader'
import myFooter from 'Components/common/myFooter'
import { mapState, mapActions } from 'vuex';
import { Dialog } from 'vant';
export default {
    data() {
        return {
            page: 2,
            title: '需求清单',
            allChecked: true,   // 总复选框开关
            countPrice: 0
        }
    },
    methods: {
        // 结算
        onSubmit() {
            Dialog.alert({
                message: '账户余额不足，请充值'
            }).then(() => {
                // on close
            });
        },
        toLook(code) {
            this.$router.push({path: '/product/' + code})
        }
    },
    computed: {
        ...mapState(['shopCar'])
    },
    components: {
        myHeader,myFooter
    },
    mounted() {
        // 获取总价
        this.shopCar.carList.merchantPromo[0].promo.some(item => {
            this.countPrice += item.singlePromo.price * item.productNum
        })  
    }
}
</script>

<style lang="scss">
    .cate-box {
        margin-top: 46px;
        margin-bottom: 100px;
        font-size: 0.14rem;
        background: #f5f5f5;
        // islogin
        .cart-login-tip {
            position: fixed;
            z-index: 99;
            top: 46px;
            left: 0;
            right: 0;
            background: #fff;
            margin-bottom: .15rem;
            text-align: center;
            padding: .1rem .15rem;
            font-size: 0.14rem;
            color: #666;
            .login-btn {
                padding: .02rem .09rem;
                color: #fff;
                margin-left: .15rem;
                background: #61b1f4;
                border-radius: .04rem;
            }
        }
        // contain
        .cart-item-contain {
            margin-bottom: .2rem;
            // title
            .cart-item-title {
                min-height: .42rem;
                line-height: .42rem;
                font-size: 0.15rem;
                padding: 0 .1rem;
                color: #333;
                border-top: 1px solid #e5e5e5;
                border-bottom: 1px solid #e5e5e5;
                background-color: #fff;
                position: relative;
                .cart-item-rxtips {
                    display: block;
                    line-height: .15rem;
                    font-size: .11rem;
                    padding: 0 0 .1rem .27rem;
                    color: #666;
                    margin-top: -.08rem;
                }
            }
            // body
            .cart-item-body {
                background-color: #eee;
                .item {
                    background-color: #ccc;
                    margin-bottom: .04rem;
                    .item-info {
                        display: flex;
                        .litteXB {
                            display: flex;
                            align-items: center;
                            padding: 10px;
                            background: #fafafa;
                        }
                        .van-card {
                            flex: 1;
                            padding-top: 10px;
                            margin-top: 0;
                            .van-card__content {
                                display: flex;
                                flex-direction: column;
                                justify-content: space-around;
                                .van-card__title {
                                    color: #666;
                                    font-size: 14px;
                                }
                            }
                        }
                    }
                    .item-gift {
                        display: flex;
                        background-color: #fff;
                        padding: .1rem .1rem;
                        color: #999;
                        line-height: 1.2;
                        font-size: 12px;
                        .item-gift-title {
                            flex: 0 0 0.55rem;
                        }
                        .item-gift-text {
                            flex: auto;
                            li {
                                overflow: hidden;
                                margin-bottom: .03rem;
                                .gift-name {
                                    width: 1.9rem;
                                    float: left;
                                    overflow: hidden;
                                    text-overflow: ellipsis;
                                    white-space: nowrap;
                                }
                                .gift-quantity {
                                    float: right;
                                }
                            }
                        }
                    }
                }
            }
        }
        // van-submit-bar
        .van-submit-bar {
            bottom: 51px;
            border-top: 1px solid #e3e3e3;
            border-bottom: 1px solid #e3e3e3;
            .van-checkbox {
                margin-left: 0.1rem;
                .van-checkbox__label {
                    font-size: 0.16rem;
                }
            }
        }
    }
</style>
